from dash import html
import pandas as pd

def get_stu_info(stu_info:dict) -> dict[str, str]:
    ret_val = {
            "姓名": "N/A", 
            "性别": "N/A", 
            "民族": "N/A",
            "出生日期": "N/A", 
            "政治面貌": "N/A",
            "班级": "N/A",
            "学期": "N/A",
            "家庭住址": "N/A",
            "家庭类型": "N/A",
            "住校": "N/A",
            "宿舍号": "N/A",
            "退学": "N/A"
        }
    if len(stu_info) != 0:
            ret_val["姓名"] = str(stu_info['bf_Name'].values[0]),
            ret_val["性别"] = str(stu_info['bf_sex'].values[0]),
            ret_val["民族"] = str(stu_info['bf_nation'].values[0]),
            ret_val["出生日期"] = str(int(stu_info['bf_BornDate'].values[0])),
            ret_val["政治面貌"] = str(stu_info['bf_policy'].values[0]),
            ret_val["班级"] = str(stu_info['cla_Name'].values[0]),
            ret_val["学期"]= str(stu_info['cla_term'].values[0]),
            ret_val["家庭住址"] = str(stu_info['bf_NativePlace'].values[0]) if not pd.isna(stu_info['bf_NativePlace'].values[0]) else "未知",
            ret_val["家庭类型"] = str(stu_info['Bf_ResidenceType'].values[0]),
            ret_val["住校"] = "是" if not pd.isna(stu_info['bf_zhusu'].values[0]) else "否",
            ret_val["宿舍号"] = str(int(stu_info['bf_qinshihao'].values[0])) if not pd.isna(stu_info['bf_qinshihao'].values[0]) else "无",
            ret_val["退学"] = str(stu_info['bf_leaveSchool'].values[0]) if not pd.isna(stu_info['bf_leaveSchool'].values[0]) else "否"
    return ret_val

def stu_info(stu_info: dict) -> html.Div:
    info = get_stu_info(stu_info)
    stu_info_div = html.Div([
        html.Table([
            html.Tr([html.Td("姓名"), html.Td(info['姓名'])]),
            html.Tr([html.Td("性别"), html.Td(info['性别'])]),
            html.Tr([html.Td("民族"), html.Td(info['民族'])]),
            html.Tr([html.Td("出生日期"), html.Td(info['出生日期'])]),
            html.Tr([html.Td("政治面貌"), html.Td(info['政治面貌'])]),
            html.Tr([html.Td("班级"), html.Td(info['班级'])]),
            html.Tr([html.Td("学期"), html.Td(info['学期'])]),
            html.Tr([html.Td("家庭住址"), html.Td(info['家庭住址'])]),
            html.Tr([html.Td("家庭类型"), html.Td(info['家庭类型'])]),
            html.Tr([html.Td("住校"), html.Td(info['住校'])]),
            html.Tr([html.Td("宿舍号"), html.Td(info['宿舍号'])]),
            html.Tr([html.Td("退学"), html.Td(info['退学'])])
        ], style={'width': '80%', 'display': 'table', 'tableLayout': 'fixed'})
    ])
    return stu_info_div